package com.circles.group.dao.sqlmap;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.circles.group.dao.GroupDao;
import com.circles.group.entity.GroupDto;
import com.circles.user.entity.UserDto;

@Repository
public class SqlMapGroupDao implements GroupDao {

	@Autowired
	private SqlSession sqlSession;
	
	@Override
	public List<HashMap<String, String>> searchGroupName(String name) {
		return sqlSession.selectList("GroupMapper.groupSearchName", name);
	}

	@Override
	public GroupDto searchGroupUrl(String url) {
		return sqlSession.selectOne("GroupMapper.searchGroupUrl", url);
	}

	@Override
	public int checkSignupGroup(HashMap<String, Object> map) {
		return sqlSession.selectOne("GroupMapper.checkSignupGroup", map);
	}

	@Override
	public int getGroupMemberCount(long group_id) {
		return sqlSession.selectOne("GroupMapper.getGroupMemberCount", group_id);
	}

	@Override
	public List<UserDto> getGroupMemberDto(long group_id) {
		return sqlSession.selectList("GroupMapper.getGroupMemberDto",group_id);
	}

	@Override
	public int checkGroupName(String name) {
		return sqlSession.selectOne("GroupMapper.checkGroupName", name);
	}

	@Override
	public int checkGroupUrl(String url) {
		return sqlSession.selectOne("GroupMapper.checkGroupUrl", url);
	}

	@Override
	public int createGroupPr(HashMap<String, String> map) {
		return sqlSession.insert("GroupMapper.createGroupPr", map);
	}

	@Override
	public void insertGroupMember(HashMap<String, String> map) {
		sqlSession.insert("GroupMapper.insertGroupMember", map);
	}

	@Override
	public List<HashMap<String, String>> searchGroupPr(HashMap<String, String> map) {
		return sqlSession.selectList("GroupMapper.searchGroupPr", map);
	}

	@Override
	public int getGroupAccess(String id) {
		return sqlSession.selectOne("GroupMapper.getGroupAccess", id);
	}

	@Override
	public int joinGroup(HashMap<String, String> map) {
		return sqlSession.insert("GroupMapper.joinGroup", map);
	}
}
